package gui.utilitarias;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import recados.Recados;

public class Comfirma extends Alert implements CommandListener {

    public static final int SIM = 0;
    public static final int NAO = 1;
    private final Command cmdSair;
    private final Command cmdCancelar;
    private int id;
    private ComfirmaListener listener;
    private final Displayable caller;

    public Comfirma(Displayable caller, String titulo, String mensagem) {
        super(titulo);

        cmdSair = new Command("Sim", Command.OK, 0);
        cmdCancelar = new Command("Não", Command.BACK, 1);

        addCommand(cmdSair);
        addCommand(cmdCancelar);

        setString(mensagem);

        this.caller = caller;

        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdCancelar) {
            Recados.setCurrent(caller);
            listener.retornoComfirma(id, NAO);
        } else if (c == cmdSair) {
            Recados.setCurrent(caller);
            listener.retornoComfirma(id, SIM);
        }
    }

    public void setListener(ComfirmaListener listener) {
        this.listener = listener;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
